package com.shengzai.rdd

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo5Filter {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("Filter")
    val sc = new SparkContext(conf)

    val stuRDD: RDD[String] = sc.textFile("hadoop_code/src/data/students.txt")
    val mapRDD: RDD[(String, String)] = stuRDD.map(
      line => {
        val split: Array[String] = line.split(",")
        (split(1), split.last)
      }
    )
    //过滤出文科一班的学生
    val filterRDD: RDD[(String, String)] = mapRDD.filter(tuple2 => {
      "文科一班".equals(tuple2._2)
    })
    filterRDD.foreach(println)

  }

}
